<template>
  <div>
    <div class="reportBox tborder">
      <el-form :model="dataForm" size="mini" inline ref="dataForm" :rules="dataRule">
        <div class="boxRow">
          <div class="rowItem br">
            <el-form-item label="舱单上运单总数：" prop="BILL_COUNT">
              <el-input v-model="dataForm.BILL_COUNT" placeholder>
                <template slot="append">票</template>
              </el-input>
            </el-form-item>
          </div>
          <div class="rowItem br">
            <el-form-item label="实际收到运单数：" prop="BILL_REALLY_COUNT">
              <el-input v-model="dataForm.BILL_REALLY_COUNT" placeholder>
                <template slot="append">票</template>
              </el-input>
            </el-form-item>
          </div>
          <div class="rowItem br">
            <el-form-item label="进港货邮件数：" prop="INCOMINGMAIL_COUNT">
              <el-input v-model="dataForm.INCOMINGMAIL_COUNT" placeholder>
                <template slot="append">件</template>
              </el-input>
            </el-form-item>
          </div>
          <div class="rowItem br">
            <el-form-item label="进港货邮重量：" prop="INCOMINGMAIL_WEIGHT">
              <el-input v-model="dataForm.INCOMINGMAIL_WEIGHT" placeholder>
                <template slot="append">KG</template>
              </el-input>
            </el-form-item>
          </div>
        </div>
        <div class="boxRow">
          <div class="rowItem br">
            <el-form-item label="邮件件数：">
              <el-input v-model="dataForm.MAIL_COUNT" placeholder>
                <template slot="append">件</template>
              </el-input>
            </el-form-item>
          </div>
          <div class="rowItem br">
            <el-form-item label="邮件重量：">
              <el-input v-model="dataForm.MAIL_WEIGH" placeholder>
                <template slot="append">KG</template>
              </el-input>
            </el-form-item>
          </div>
          <div class="rowItem br">
            <el-form-item label="运费预付运单总数：" prop="PAY_ADVANCE_BILL_COUNT">
              <el-input v-model="dataForm.PAY_ADVANCE_BILL_COUNT" placeholder>
                <template slot="append">件</template>
              </el-input>
            </el-form-item>
          </div>
          <div class="rowItem">
            <el-form-item label="运费到付运单总数：">
              <el-input v-model="dataForm.PAY_BILL_COUNT" placeholder>
                <template slot="append">KG</template>
              </el-input>
            </el-form-item>
          </div>
        </div>

        <div class="boxRow" v-if="dataForm.MAIL_COUNT>0">
          <div style="display:flex;padding-left:20px;align-items: center;">
            <el-form-item label="运费到付运单号：" prop="PAYMENT_BILL_NO"></el-form-item>
          </div>
          <div class="rowItem">
            <el-form-item>
              <el-input v-model="dataForm.PAYMENT_BILL_NO" placeholder></el-input>
            </el-form-item>
          </div>
        </div>
        <div class="boxRow">
          <div style="display:flex;padding-left:20px;align-items: center;">
            <el-form-item label="是否收到FFM：" prop="FFM_CHECK"></el-form-item>
          </div>
          <div class="rowItem">
            <el-radio-group v-model="dataForm.FFM_CHECK">
              <el-radio label="是">是</el-radio>
              <el-radio label="否">否</el-radio>
            </el-radio-group>
          </div>
        </div>

        <div class="boxRow">
          <div style="display:flex;padding-left:20px;align-items: center;">
            <el-form-item label="多单信息汇总：" prop="EXXESS_MESSAGE"></el-form-item>
          </div>
          <div class="rowItem">
            <el-input
              type="textarea"
              :autosize="{ minRows: 2, maxRows:10}"
              placeholder="请输入内容"
              v-model="dataForm.EXXESS_MESSAGE"
            ></el-input>
          </div>
        </div>
        <div class="boxRow">
          <div style="display:flex;padding-left:20px;align-items: center;">
            <el-form-item label="少单信息汇总：" prop="MISS_MESSAGE"></el-form-item>
          </div>
          <div class="rowItem">
            <el-input
              type="textarea"
              :autosize="{ minRows: 2, maxRows:10}"
              placeholder="请输入内容"
              v-model="dataForm.MISS_MESSAGE"
            ></el-input>
          </div>
        </div>
        <div style="text-align:right;padding:10px 20px" v-if="formId">
          <!-- <el-button type="primary">修改</el-button> -->
          <el-button v-if="isAuthBtn('extra2')" size="mini" type="success" @click="dataFormSubmit()">保存</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    formId: {
      default: 0
    }
  },
  data() {
    return {
      dataForm: {},
      dataRule: {
        BILL_COUNT: [
          { required: true, message: "舱单上运单总数不能为空", trigger: "blur" }
        ],
        BILL_REALLY_COUNT: [
          { required: true, message: "实际收到运单数不能为空", trigger: "blur" }
        ],
        INCOMINGMAIL_COUNT: [
          { required: true, message: "进港货邮件数不能为空", trigger: "blur" }
        ],
        INCOMINGMAIL_WEIGHT: [
          { required: true, message: "进港货邮重量不能为空", trigger: "blur" }
        ],
        PAY_ADVANCE_BILL_COUNT: [
          {
            required: true,
            message: "运费预付运单总数不能为空",
            trigger: "blur"
          }
        ],
        PAYMENT_BILL_NO: [
          { required: true, message: "运费到付运单号不能为空", trigger: "blur" }
        ],
        FFM_CHECK: [
          { required: true, message: "是否收到FFM不能为空", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    init(data) {
      this.dataForm = Object.assign({}, this.dataForm, data);
    },
    dataFormSubmit() {
      let dataForm = this.dataForm;
      let that = this;
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          if (
            !dataForm.PAY_BILL_COUNT ||
            !dataForm.EXXESS_MESSAGE ||
            !dataForm.MISS_MESSAGE
          ) {
            let info = "";
            if (!dataForm.PAY_BILL_COUNT) {
              info += "运费到付运单总数/";
            }
            if (!dataForm.EXXESS_MESSAGE) {
              info += "多单信息汇总/";
            }
            if (!dataForm.MISS_MESSAGE) {
              info += "少单信息汇总/";
            }

            that
              .$confirm(info + "等信息未输入, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
              })
              .then(() => {
                this.updateSumit();
              });
          } else {
            this.updateSumit();
          }
        }
      });
    },
    updateSumit() {
      this.$http({
        url: this.$http.adornUrl(`/air/airReport_documentation_save`),
        method: "post",
        data: this.$http.adornData(this.dataForm)
      }).then(({ data }) => {
        if (data.result == "1") {
          this.$message({
            message: "操作成功",
            type: "success",
            duration: 1500,
            onClose: () => {
              this.$emit("refsherData", sessionStorage.reportid);
            }
          });
        } else {
          this.$message.error(data.message);
        }
      });
    }
  }
};
</script>

<style lang="scss">
.reportBox {
  border: 2px solid #eee;
  width: 900px;
  margin: 10px;
  .el-form-item {
    margin: 0;
  }
}
.boxRow {
  display: flex;
  border-bottom: 1px solid #e6e6e6;
}
.br {
  border-right: 1px solid #e6e6e6;
}
.boxtitle {
  padding: 20px;
}
.rowItem {
  flex: 1;
  padding-left: 15px;
  padding-right: 15px;
  display: flex;
  align-items: center;
}
.pr20 .rowItem {
  padding-right: 20px;
}
.table--border {
  border-collapse: collapse;
  margin-top: 10px;
}
.table--border th {
  padding: 10px;
}
.tborder {
  td,
  th {
    border: 1px solid #e6e6e6;
    padding-left: 10px;
  }
}
</style>